package com.eorchis.module.signupdept.service.impl;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.eorchis.core.basedao.condition.BaseTreeCondition;
import com.eorchis.core.basedao.dao.IDaoSupport;
import com.eorchis.core.basedao.entity.IBaseEntity;
import com.eorchis.core.servicetemplate.treetemplate.DndTreeTemplate;
import com.eorchis.core.servicetemplate.treetemplate.jsonbean.JsonTreeBean;
import com.eorchis.module.department.domain.Department;
import com.eorchis.module.department.domain.DepartmentTreeCondition;
import com.eorchis.module.department.manager.IDepartmentTreeManager;
import com.eorchis.module.signupdept.dao.ISignupDeptDao;
import com.eorchis.module.signupdept.domain.SignupDept;
import com.eorchis.module.signupdept.service.ISignupDeptTreeService;
import com.eorchis.module.signupdept.ui.commond.SignupDeptValidCommond;

/**
 * Title: SignupDeptServiceImpl<br>
 * Description: 报名单位管理业务接口实现<br>
 * Company: GoldGov<br>
 * Copyright @ 2012 GoldGov .All rights reserved.<br>
 * @author Max
 * @createDate 2014-12-29
 * @version $Revision$
 */
// 声明本类为Server实现类，声明bean名称
@Service(value = "com.eorchis.module.signupdept.service.impl.SignupDeptTreeServiceImpl")
public class SignupDeptTreeServiceImpl 
			extends DndTreeTemplate
		implements ISignupDeptTreeService {
		
	@Autowired
	@Qualifier("com.eorchis.module.signupdept.dao.impl.SignupDeptDaoImpl")
	private ISignupDeptDao signupDeptDao;
	
	@Autowired
	@Qualifier("com.eorchis.module.department.manager.impl.DepartmentTreeManagerImpl")
	private IDepartmentTreeManager departmentTreeManager;

	public IDaoSupport getDaoSupport() {
		return signupDeptDao;
	}
	@SuppressWarnings("unchecked")
	public SignupDeptValidCommond toCommond(IBaseEntity entity) {
		return new SignupDeptValidCommond((SignupDept)entity);
	}
	
	/**
	 * 报名部门树查询
	 * 
	 * @param condition
	 * @return
	 * @author Max
	 * @createDate 2014-12-29
	 */
	protected List<?> findNextNodeList(BaseTreeCondition condition) throws Exception {
		return signupDeptDao.listDepartmentTree((DepartmentTreeCondition) condition);
	}
	@Override
	public void doDndProcess(BaseTreeCondition condition) throws Exception {
		// TODO Auto-generated method stub
		
	}
	@Override
	public List<JsonTreeBean> doProcess(BaseTreeCondition condition)
			throws Exception {
		return process(condition);
	}
	@Override
	protected void updateTreeParentID(BaseTreeCondition condition)
			throws Exception {
		// TODO Auto-generated method stub
		
	}
	@Override
	protected void updateTreeOrderNum(BaseTreeCondition condition)
			throws Exception {
		// TODO Auto-generated method stub
		
	}
	@Override
	protected boolean isLeapNode(BaseTreeCondition condition) throws Exception {
		if (condition.getBasebean() != null) {
			condition.setBasebean(null);
		}
		return signupDeptDao.isLeapNode((DepartmentTreeCondition) condition);
	}
	@Override
	protected List<JsonTreeBean> objListToJsonList(List<?> treeNodeList)
			throws Exception {
		List<JsonTreeBean> resultList = new ArrayList<JsonTreeBean>();
		for (Object obj : treeNodeList) {
			SignupDept department = (SignupDept) obj;
			JsonTreeBean jtBean = new JsonTreeBean();
			jtBean.setId(department.getDepid().toString());
			jtBean.setText(department.getDepname());
			jtBean.setParentID(department.getParentId());
			resultList.add(jtBean);
		}
		return resultList;
	}
	
	
	protected List<JsonTreeBean> objListToJsonList(List<?> treeNodeList,
			BaseTreeCondition condition) throws Exception {
		List resultList = new ArrayList();
		for (Iterator i$ = treeNodeList.iterator(); i$.hasNext();) {
			Object obj = i$.next();
			SignupDept department = (SignupDept) obj;
			JsonTreeBean jtBean = new JsonTreeBean();
			jtBean.setId(department.getDepid().toString());
			jtBean.setText(department.getDepname());
			resultList.add(jtBean);
		}
		return resultList;
	}

}
